<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-项目信息新增</title>
    <script src="/scripts/boot.js"></script>
    <link href="/scripts/daterangepicker/js/daterangepicker.min.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/daterangepicker/js/moment.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/js/jquery.daterangepicker.min.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/ux.daterangepicker.js" type="text/javascript"></script>
    <link href="/scripts/daterangepicker/css/skin.css" rel="stylesheet" type="text/css" />
    <style>
        html body .searchbox .mini-buttonedit-icon
        {
            /*background:url(static/scripts/daterangepicker/search.gif) no-repeat 50% 50%;*/
        }
        .rangeHidden{
            display: none;
        }
    </style>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>基本信息</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="160px"></col>
            <col width="50%"></col>
            <col width="160px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">计划名称</td>
            <td>
                <input name="id" id="id" class="mini-hidden"/>
                <input name="planNodeId" id="planNodeId" class="mini-hidden"/>
                <input type="text" name="planName" class="mini-textbox w250" enabled="false" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>
            <td class="text-titlebg">
                要调整的计划任务
            </td>
            <td>
                <input type="text" name="nodeName" class="mini-textbox w250" enabled="false" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>
        </tr>

        <tr>
            <td class="text-titlebg">
                计划起止时间
            </td>
            <td>
                <input id="date-range1" class="uc-daterangepicker searchbox w250" name="beginDate" enabled="false"/>
            </td>
            <td class="text-titlebg" >
                调整类型
            </td>
            <td>
                <select name="adjustType" class="mini-combobox w250" ajaxType="post" url="/dictionary/listValues?name=adjustType" textField="value" valueField="id" errorMode="none" onvalidation="onChoseValidation"  onvaluechanged="view.valuechangedText" required="true" requiredErrorText="请选择"></select>
            </td>
        </tr>


        <tr id="rangeText" class="rangeHidden">
            <td class="text-titlebg">
                <span class="color-red"></span>结束时间调整到
            </td>
            <td>
                <input id="date-range" class="mini-datepicker searchbox w250" name="delayDate" allowInput="false" showTodayButton="false" ondrawdate="view.onDrawDate" onvaluechanged="view.changeTime"/>
            </td>
            <td class="text-titlebg">
                <span class="color-red"></span>调整工期
            </td>
            <td>
                <div class="input-div color-66" id="adjustDeadline"></div>
                <input type="text"  id="adjustDeadline" name="adjustDeadline" enabled="false" class="mini-textbox w250" errorMode="none"/>
            </td>
        </tr>
        <tr id="range2Text" class="rangeHidden">
            <td class="text-titlebg">
                <span class="color-red"></span>调整到起止时间
            </td>
            <td>
                <input id="date-range2" class="uc-daterangepicker searchbox w250" name="adjustDate" allowInput="false" showTodayButton="false" ondrawdate="view.onDrawDate"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">申请原因</td>
            <td colspan="3">
                <textarea name="remark" class="mini-textarea wtextarea" emptyText=""></textarea>
            </td>
        </tr>
    </table>
    <div class="title-info"><span>影响的节点计划</span></div>
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:260px; margin-top: 10px;" url="/planNodeAdjust/affectedListByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="false">
        <div property="columns">
            <div type="indexcolumn"width="35" headerAlign="center" align="center">编号</div>
            <div field="planName" width="120" headerAlign="center" allowSort="true">计划名称</div>
            <div field="remark" width="120" headerAlign="center" allowSort="true">说明</div>
            <div field="postName" width="120" headerAlign="center" allowSort="true">负责岗位</div>
            <div field="beginDate" width="120" headerAlign="center" allowSort="true">计划起止时间</div>
            <div field="deadlineDesc" width="120" headerAlign="center" allowSort="true">工期说明</div>
        </div>
    </div>
    <div class="mini-fit"></div>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
        <a class="chose-button save-button" onclick="view.save()">发送审批</a>
    </div>
</div>
<script src="/scripts/res/js/common.js"></script>
<script type="text/javascript">
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
    var post_flag,form,state,datas;
    var view = {
        init: function () {
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
            mini.get("datagrid1").on("drawcell", function (e) {
                var column = e.column;
                if(column.field=="beginDate"){
                    e.cellHtml = e.row.beginDate.substring(0,10)+'至'+e.row.endDate.substring(0,10);
                }
            })
        },
        //保存
        save: function () {
            form.validate();
            if (form.isValid() == false) return;
            if (post_flag) return;
            var data = form.getData(true);//获取表单多个控件的数据
            console.log(data)
            data['planNode.id']=data.planNodeId;
            delete data["planNodeId"];
            data['adjustType.id']=data.adjustType;
            delete data["adjustType"];
            data['endDate']=data.beginDate.substring(data.beginDate.length-10,data.beginDate.length);
            data['beginDate']=data.beginDate.substring(0,10);
            if(!data.delayDate){
                delete data["delayDate"];
                delete data["adjustDate"];
            }
            else{
                data['adjustEndDate']=data.adjustDate.substring(data.adjustDate.length-10,data.adjustDate.length);
                data['adjustBeginDate']=data.adjustDate.substring(0,10);
            }

            post_flag = true;
            $.ajax({
                url: ("/planNodeAdjust/edit"),
                type: "post",
                data: data,
                success: function (msg) {
                    post_flag = false;
                    common.unmask();
                    CloseWindow("ok");
                },
                error: function (errorMsg) {
                    post_flag = false;
                    common.unmask();
                }
            });
        },
//    数据展示
        SetData: function (data) {
            data = mini.clone(data);
            console.log(data)
            state = data.state;
            mini.get("datagrid1").load({"id":data.planNodeId});
            mini.get("planNodeId").setValue(data.id);
            $.ajax({
                url:"/planNodeAdjust/info?id=" + data.id,
                type: "post",
                success: function (text) {
                    var obj = JSON.parse(text);
                    //跨页面传递的数据对象，克隆后才可以安全使用
                    datas = mini.decode(obj.body[0]);   //反序列化成对象
                    form.setData(datas);             //设置多个控件数据
                    var beDate;
                    $.each(datas,function(key,value){
                        if(key=="beginDate"){
                            beDate=value;
                        }
                        if(key=="endDate"){
                            if(value){
                                beDate=beDate+" 至 "+value;
                            }
                            mini.get("date-range1").setValue(beDate);
                        }
                        if(key=="adjustType"){
                            if(value==226){
                                $("#rangeText").removeClass('rangeHidden');
                                $("#range2Text").addClass('rangeHidden');

                            }else if(value==227){
                                $("#range2Text").removeClass('rangeHidden');
                                $("#rangeText").addClass('rangeHidden');
                            }else{
                                $("#rangeText").addClass('rangeHidden');
                                $("#range2Text").addClass('rangeHidden');
                            }
                        }
                    });
                    mini.get("date-range1").setValue(datas.beginDate +" ~ " +datas.endDate);

                    mini.get("date-range").setValue(datas.delayDate);
                    mini.get("date-range2").setValue(datas.adjustBeginDate +" ~ " +datas.adjustEndDate);
                }
            });
        },
        valuechangedText: function (e) {
            if(e.value==226){
                $("#rangeText").removeClass('rangeHidden');
                $("#range2Text").addClass('rangeHidden');
                mini.get("date-range2").setValue(datas.endDate);
                mini.get("date-range").setValue(datas.endDate);

            }else if(e.value==227){
                mini.get("date-range2").setValue(datas.endDate);
                mini.get("date-range").setValue(datas.endDate);
                mini.get("adjustDeadline").setValue(0);
                $("#range2Text").removeClass('rangeHidden');
                $("#rangeText").addClass('rangeHidden');
            }else{
                mini.get("date-range").setValue("");
                mini.get("date-range2").setValue("");
                mini.get("adjustDeadline").setValue(0);
                $("#rangeText").addClass('rangeHidden');
                $("#range2Text").addClass('rangeHidden');
            }
        },
        onDrawDate: function (e) {
            var date = e.date;
            if (date.getTime() < new Date(datas.endDate).getTime()) {
                e.allowSelect = false;
            }
        },
        changeTime: function (e) {
            var yyyymmdd=e.value.Format("yyyy-MM-dd");
            var adjustDeadline=(new Date(yyyymmdd).getTime()-new Date(datas.endDate).getTime())/(1000*60*60*24);
            mini.get("adjustDeadline").setValue(adjustDeadline);
        }
    };
    view.init();
</script>
</body>
</html>